DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME

SET @StartDate = '2008/10/01'
SET @EndDate = '2008/10/31'


SELECT (DATEDIFF (dd, @StartDate, @EndDate) + 1) - (DATEDIFF (wk, @StartDate, @EndDate) * 2)
       -(
           CASE 
                WHEN DATENAME (dw, @StartDate) = 'Sunday' THEN 1
                ELSE 0
           END
       )
       -(
           CASE 
                WHEN DATENAME (dw, @EndDate) = 'Saturday' THEN 1
                ELSE 0
           END
       )

SELECT SUM(
           CASE 
                WHEN strday IN ('Saturday', 'Sunday') THEN 1
                ELSE 0
           END
       )  AS TWorkdays
FROM   (
           SELECT DATENAME (dw, DATEADD (DAY, sv.number, @StartDate)) AS StrDay, sv.number
           FROM   [master].dbo.spt_values sv
           WHERE  sv.number < DAY(@EndDate) AND
                  sv.[type] = 'p'
       )     X
       
       
       SELECT DATENAME (dw, DATEADD (DAY, sv.number, @StartDate)) AS StrDay, sv.number
           FROM   [master].dbo.spt_values sv
           WHERE  sv.number < DAY(@EndDate) AND
                  sv.[type] = 'p'